import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

const tableName = 'Article';

export const createArticle = async (data) => {
    try {
        const res = await prisma[tableName].create({
            data,
        });
        console.log('数据插入成功',res.id);
    } catch (error) {
        console.log('数据插入失败',error.message);
        throw error.message;
    } finally {
        await prisma.$disconnect();
    }
};
export const getUserByName =async (name) =>{
    return await prisma[tableName].findFirst({
        where: {
            name: name,
        },
        orderBy: {
            timestamp: 'desc',
        },
    });
}
